from django.contrib.auth.backends import ModelBackend
from user.models import User
from django.db.models import Q
class Authenticate(ModelBackend):

    def authenticate(self, request, username=None, password=None, **kwargs):

        try:
            user = User.objects.get(
                Q(username=username) | Q(mobile=username)
            )
        except User.DoesNotExist as e:

            return None

        return user

